<!DOCTYPE html>
<html>
	
	<head>
		<meta charset="UTF-8">
		<title></title>
	<script>
		function tupian(){
			var num=document.getElementById("s");
			var xml_request;
			if (window.XMLHttpRequest) {
				xml_request = new XMLHttpRequest();
			} else if(window.ActiveXObject){
				try{
					xml_request = new  ActiveXObject("Msxml2.XMLHTTP")
				}catch(e){
					//TODO handle the exception
					try{
						xml_request = new  ActiveXObject("Microsoft.XMLHTTP")
					}catch(e){
						//TODO handle the exception
						alert("你的浏览器不支持AJAx！");
					}
				}
			}
			xml_request.open("GET","image.xml",false);
			xml_request.send();
			var b=xml_request.responseXML;
			var imags=b.getElementsByTagName("name");
			
			for (i=0;i<imags.length;i++) {
				num.options[i]=new Option(imags[i].childNodes[0].nodeValue);;
			}
			
		}
		function fun(){
		var num=document.getElementById("s");
		var st="url(img/"+num.value+")";
		var getbody=document.getElementsByTagName("body")[0];
		getbody.style.background=st;
		
		
		}
	</script>
	</head>
	<body onload="tupian()" background="img/Chrysanthemum.jpg">
	<!-- 
		1、在网页中有一个下拉列表 select  option
		2、选项是图片的名字
		3、将所有的图片名字存到xml文件中，用Ajax读取xml文档
		4、当你选中其中一项，将对应的图片做成网页背景
	-->选择背景图：
	<select id="s" onchange="fun()">
		
	</select>
	</body>
</html>
